/**
 * 
 */
package com.swg.cocobox.message;

import java.nio.charset.Charset;

import com.swg.cocobox.message.internal.ASCIIMessageBuilder;
import com.swg.cocobox.message.internal.ASCIIMessageParser;
import com.swg.cocobox.message.internal.EncodedClientInfoParser;
import com.swg.cocobox.message.internal.UTFMessageBuilder;
import com.swg.cocobox.message.internal.UTFMessageParser;

/**
 * @author satriaprayoga
 *
 */
public abstract class MessageContext {

	public static final int LOGIN=1;
	public static final int LOGOUT=2;
	public static final int MESSAGE=3;
	public static final int CLIENTLST=4;
	
	public static final int PRIVATE=5;
	public static final int BROADCAST=6;
	
	public static final int PRIVATE_OK=200;
	public static final int BROADCAST_OK=201;
	public static final int LOGIN_OK=202;
	public static final int PRIVATE_FAILED=404;
	public static final int BROADCAST_FAILED=405;
	public static final int LOGIN_FAILED=406;
	
	public static final int CONNECTION_EVENT=0;
	public static final int RECEIVE_EVENT=1;
	public static final int SEND_EVENT=2;
	
	public static final int LOGIN_EVENT=3;
	
	public static final String LOG_IN="login";
	public static final String PM="private";
	public static final String BR="broadcast";
	public static final String LOG_OUT="logout";
	public static final String CLIENTS="clients";
	
	public static enum MessageEncoding{
		ASCII,UTF_8
	}
	
	public static final MessageFactory getMessageFactory(MessageEncoding encoding){
		if(encoding==MessageEncoding.ASCII){
			return new ASCIIMessageFactory();
		}else if(encoding==MessageEncoding.UTF_8){
			return new UTFMessageFactory();
		}else{
			return null;
		}
	}
	
	public static final ClientInfoParser getClientInfoParser(MessageEncoding encoding){
		if(encoding==MessageEncoding.ASCII){
			return new EncodedClientInfoParser(Charset.forName("US-ASCII"));
		}else if(encoding==MessageEncoding.UTF_8){
			return new EncodedClientInfoParser(Charset.forName("UTF-8"));
		}else{
			return null;
		}
	}
	
	private static final class ASCIIMessageFactory extends MessageFactory{

		public ASCIIMessageFactory() {
			super(new ASCIIMessageBuilder(), new ASCIIMessageParser());
		}
		
	}
	
	private static final class UTFMessageFactory extends MessageFactory{

		public UTFMessageFactory() {
			super(new UTFMessageBuilder(), new UTFMessageParser());
		}
		
	}
}
